package cn.yunxiang.summer.framework.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wangqx
 * @description TODO
 * @date 2022/6/16
 */
public class BaseConverter<V,D,T> {

    /**
     * dto转vo
     * @param t
     * @return
     */
    public V convertToVO(T t){
        return null;
    }

    /**
     * dto列表转vo
     * @param tList
     * @return
     */
    public List<V> convertToVO(List<T> tList){
        return tList.stream().map(t->convertToVO(t)).collect(Collectors.toList());
    }
    /**
     * dto分页转vo
     * @param tPage
     * @return
     */
    public IPage<V> convertToVO(IPage<T> tPage){
        IPage<V> vPage=new Page<>();
        vPage.setCurrent(tPage.getCurrent());
        vPage.setSize(tPage.getSize());
        vPage.setTotal(tPage.getTotal());
        vPage.setRecords(convertToVO(tPage.getRecords()));
        return vPage;
    }




    /**
     * dto转po
     * @param d
     * @return
     */
    public T convertToPo(D d){
        return null;
    }

}
